﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Mimoza.GUI;
using Mimoza.Common;
using Mimoza.ObjectLayer;
using Mimoza.RdpPlugin;

namespace SetupWiz
{
    public partial class NewRDPConnection : UserControl, Mimoza.GUI.IWizardPage
    {
        public NewRDPConnection()
        {
            InitializeComponent();
        }
        #region IWizardPage Members
        private IWizard m_wizard;

        private bool m_IsConfigured = true;

        public void Init(Mimoza.GUI.IWizard wizard)
        {
            m_wizard = wizard;
        }

        public void EnterPage()
        {
        }

        public bool Try2LeavePage(Mimoza.GUI.WizardPageLeavingDirection direction)
        {
            if (direction == WizardPageLeavingDirection.Change)
            {
                if (null == this.connection.Text || this.connection.Text.Length == 0 || 
                    null == this.server.Text || this.server.Text.Length == 0)
                {
                    MessageBox.Show(Resource.Error_EmptyNames, Resource.Error_CaptionErrorInNames, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return false;
                }

                foreach (char c in Resource.InvalidCharacters)
                {
                    if (this.connection.Text.Contains(c))
                    {
                        MessageBox.Show(Resource.Error_InvalidCharInNames + Resource.InvalidCharacters, Resource.Error_CaptionErrorInNames, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return false;
                    }
                }

                foreach (char c in Resource.InvalidCharacters)
                {
                    if (this.server.Text.Contains(c))
                    {
                        MessageBox.Show(Resource.Error_InvalidCharInNames + Resource.InvalidCharacters, Resource.Error_CaptionErrorInNames, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return false;
                    }
                }
            }

            (m_wizard.UserData as RdpData).SessionName = this.connection.Text;
            (m_wizard.UserData as RdpData).Computer = this.server.Text;

            m_IsConfigured = true;
            return true;
        }

        public Mimoza.GUI.IWizard Wizard
        {
            get
            {
                return m_wizard;
            }
        }

        public string PageName
        {
            get { return Resource.RDPConnection_PageName; }
        }

        public string PageTitle
        {
            get { return Resource.RDPConnection_PageTitle; }
        }

        public bool IsConfigured
        {
            get
            {
                return m_IsConfigured;
            }
            set
            {
                m_IsConfigured = value;
            }
        }

        public event Mimoza.GUI.PageEvent OnPageModified;

        #endregion

    }
}
